package com.foreveross.fetl.core.domain.task.repository.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.foreveross.fetl.common.jpa.EntityOracleHibernateRepository;
import com.foreveross.fetl.core.domain.task.ExchangeRateEntity;
import com.foreveross.fetl.core.domain.task.repository.IExchangeRateRepository;

@Repository("exchangeRateRepository")
public class ExchangeRateRepositoryImpl extends EntityOracleHibernateRepository
		implements IExchangeRateRepository {

	@Override
	public void save(ExchangeRateEntity entity) {
		super.save(entity);

	}

	@Override
	public void delete(ExchangeRateEntity entity) {
		super.delete(ExchangeRateEntity.class, entity.getId());

	}

	@Override
	public List<ExchangeRateEntity> findByCondition(String name, String code,
			String date) {
		List<Object> list = new ArrayList<Object>();
		StringBuffer sbf = new StringBuffer(
				"from ExchangeRateEntity e where 1=1 ");
		if(null!=name && !"".equals(name)){
			sbf.append(" and e.name =?  ");
			list.add(name);
		}
		if(null!=code && !"".equals(code)){
			sbf.append(" and e.code =?  ");
			list.add(code);
		}
		if(null!=date && !"".equals(date)){
			sbf.append(" and e.date =?  ");
			list.add(date);
		}
		sbf.append(" order by e.date desc ");
		List<ExchangeRateEntity> listEntity =super.queryResult(sbf.toString(), list.toArray());
		return listEntity;
	}

}
